/*
 * Copyright 2020 tu.cn All right reserved. This software is the
 * confidential and proprietary information of tu.cn ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Tu.cn
 */
package com.onedec.message.serviceImpl;

import com.onedec.message.entity.OnedecEmp;
import com.onedec.message.entity.OnedecFriendGroup;
import com.onedec.message.entity.OnedecFriendGroupEmp;
import com.onedec.message.entity.OnedecFriendGroupExample;
import com.onedec.message.mapper.OnedecEmpMapper;
import com.onedec.message.mapper.OnedecFriendGroupEmpMapper;
import com.onedec.message.mapper.OnedecFriendGroupMapper;
import com.onedec.message.service.FriendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 31014
 * @date 2020/7/13 11:25
 */
@Service
public class FriendServiceImpl implements FriendService {

    @Resource
    private OnedecFriendGroupMapper onedecFriendGroupMapper;
    @Resource
    private OnedecFriendGroupEmpMapper onedecFriendGroupEmpMapper;
    @Resource
    private OnedecEmpMapper onedecEmpMapper;

    public List<OnedecFriendGroup> selectFriend(Integer eId) {
        final OnedecFriendGroupExample example = new OnedecFriendGroupExample();
        example.createCriteria().andEmpIdEqualTo(eId);
        final List<OnedecFriendGroup> groups = onedecFriendGroupMapper.selectByExample(example);
        groups.forEach(e -> {
            final Integer friendGroupId = e.getFriendGroupId();
            final List<Map<String, Object>> emps = onedecEmpMapper.selectByFriendGroup(friendGroupId);
            System.out.println(emps);
            e.setFriends(emps);
        });
        return groups;
    }

    public void insertFriend(Integer id, Integer group) {
        final OnedecFriendGroupEmp groupEmp = new OnedecFriendGroupEmp();
        groupEmp.setFriendGroupId(group);
        groupEmp.setFriendId(id);
        onedecFriendGroupEmpMapper.insertSelective(groupEmp);
    }
}